package com.xhj.joffer.array;
import org.junit.Test;

import java.util.Arrays;
/**
 * @author haijianxia pure_xhj@163.com
 * @Date 2021-09-16
 * @Time 14:10
 */
public class EscArraySpin {
  public static void main(String[] args) {
	  int[] numbers=new int[]{3,4,5,1,2};
	  System.out.println(Arrays.toString(numbers)+"\nmin: "+test01(numbers));

	  System.out.println("====================================================");
	  int[] numbers2=new int[]{2,2,2,0,1};
	  System.out.println(Arrays.toString(numbers2)+"\nmin: "+test01(numbers2));

  }
  /** 思路一: 找到落差 */
  @Test
  public static int test01(int[] numbers) {
  	System.out.println("\n=============test01==============");
  	System.out.println("思路一: 找到落差");
  	long time01 = System.currentTimeMillis();

  	int result =0;
  	int times=0;
    for (int i = 0; i < numbers.length-1; i++) {
      if (numbers[i]>numbers[i+1]){
      	result=numbers[i+1];times++;
      }
    }
	  // 无落差
    if(times==0){
	    if(numbers.length!=0){
		    result=numbers[0];
	    }
    }

  	long time0101  = System.currentTimeMillis() - time01;
  	System.out.println("test01 耗时 =  " + time0101  + "ms");
  	System.out.println("=================================");

  	return result;
  }
}
